package com.marion.study.controller;

import com.marion.study.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/trans")
public class TransController {

    @Autowired
    private UserService userService;

    /**
     * 事务传播性
     */
    @GetMapping("/order")
    public Object order(@RequestParam(required = false, defaultValue = "1") long uid,
                         @RequestParam(required = false, defaultValue = "1") int produceId) {

        userService.order(uid, produceId);

        return new HashMap<>() {{
            put("status", "success");
        }};
    }

}
